const domainName = getApp().globalData.domainName
const parameter = getApp().globalData.parameter

// pages/sysConfig/Test_types/Test_types.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lis:[],
  },

  set_opt(e){
    let index = e.currentTarget.id
    let stage_id = this.data.lis[index].id
    wx.showActionSheet({
      itemList: ['删除'],
      alertText: '操作选项',
      success: res => {
        if(res.tapIndex==0){
          wx.request({
            url: domainName + 'Test_stages_delete',
            data: {stage_id},...parameter,
            success: res => {
              if(res.data.delete_res){
                wx.showToast({
                  title: '删除完成！',
                })
                this.page_init(this.data.test_subjects_id)
              }
            },
          })
        }        
      },
    })
  },


  confirm_add(){
    wx.showModal({
      content: '确定提交吗？',
      title: '提示',
      success: res => {
        if(res.confirm){
          wx.request({
            url: domainName + 'Test_stages_submit',
            data: {
              name:this.data.name,
              test_subjects_id:this.data.test_subjects_id,
            },...parameter,
            success: res => {
              if(res.data.row_id){
                wx.showToast({
                  title: '提交完成！',
                })
                this.setData({show:false})
                this.page_init(this.data.test_subjects_id)
              }
            },
          })
        }
      },
    })
  },

  input_name(e){
    this.setData({
      name:e.detail.value
    })
  },

  add(){
    this.setData({show:true})
  },

  page_init(test_subjects_id){
    wx.request({
      url: domainName + 'Test_stages_init',
      data: {test_subjects_id},...parameter,
      success: res => {
        this.setData({
          lis:res.data.lis,
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log('options',options)
    let test_subjects_id = options.test_subjects_id
    let test_subjects_name = options.test_subjects_name
    this.setData({test_subjects_id,test_subjects_name})
    wx.setNavigationBarTitle({
      title: '科目：' + test_subjects_name,
      success: (res) => {},
      fail: (res) => {},
      complete: (res) => {},
    })
    this.page_init(test_subjects_id)
  },

})